package com.ftg.learn.day05.giteelogin.service;

import com.ftg.learn.day05.giteelogin.dao.UserDao;
import com.ftg.learn.day05.giteelogin.entity.UserEntity;

import java.util.Scanner;

/**
 * 用户的业务逻辑
 *
 * @author 布衣
 */
public class UserService {

    /**
     * 注册
     *
     * @param id
     * @param name
     * @param password
     * @param mail
     * @param tel
     * @param personSpace
     * @return
     */
    public boolean register(int id, String name, String password, String mail, String tel, String personSpace) {

        boolean mailBol = mail.length() >= 6 && mail.length() <= 20;
        boolean telBol = tel.length() == 11;
        boolean personSpaceBol = personSpace.length() >= 6 && personSpace.length() <= 20;
        boolean passBol = password.length() >= 6 && password.length() <= 8;

        if (!passBol) {
            throw new RuntimeException("的长度为6-8");
        }

        if (!mailBol) {
            throw new RuntimeException("邮箱的长度为6-8");
        }

        if (!telBol) {
            throw new RuntimeException("电话的长度为必须为11");
        }

        if (!personSpaceBol) {
            throw new RuntimeException("空间的长度为6-8");
        }

        UserEntity user1 = new UserEntity();
        user1.setId(id);
        user1.setName(name);
        user1.setPassword(password);
        user1.setMail(mail);
        user1.setTel(tel);
        user1.setPersonSpace(personSpace);

        UserDao userDao = new UserDao();
        userDao.register(user1);

        return true;
    }


}
